﻿using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore;
using MyStyle.Model;

namespace MyStyle.Repositry
{
    public class CustomerMap : IEntityTypeConfiguration<Customer>
    {
        public void Configure(EntityTypeBuilder<Customer> builder)
        {
            // builder.HasKey(x => x.Id).HasName("pk_customerid");
            builder.ToTable("customer");
            builder.Property(x => x.Id).ValueGeneratedOnAdd().HasColumnName("id").HasColumnType("INT");
            builder.Property(x => x.CustomerName).HasColumnName("customer_name").HasColumnType("NVARCHAR(100)");
            builder.Property(x => x.PurchasesProduct).HasColumnName("purchased_product") .HasColumnType("NVARCHAR(100)").IsRequired();
            builder.Property(x => x.PaymentType).HasColumnName("payment_type").HasColumnType("NVARCHAR(50)") .IsRequired();
            builder.Property(x => x.CreateDate) .HasColumnName("created_date") .HasColumnType("datetime");
            builder.Property(x => x.ModifyDate) .HasColumnName("modified_date").HasColumnType("datetime");
            builder.Property(x => x.IsActive).HasColumnName("is_active") .HasColumnType("bit");
            //builder.
            //// builder.
            // builder.HasMany(x => x.CustomItem).WithOne(x => x.Customer).HasForeignKey(p => p.CustomerId);
            // builder.HasMany(x => x.CustomItem).WithOne(x => x.Customer).HasForeignKey(p => p.CustomerId);
            // builder.HasOne(x => x.CustomItem).WithMany().HasForeignKey(p => p.Id);
            builder.HasMany(b => b.CustomItem).WithOne(p => p.Customer).HasForeignKey(p => p.CustomerId);
        }
    }
}
